<html>
<head><meta charset="utf-8"><title>Cross-compiling for aarch64? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Cross-compiling.20for.20aarch64.3F.html">Cross-compiling for aarch64?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="216832371"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Cross-compiling%20for%20aarch64%3F/near/216832371" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Cross-compiling.20for.20aarch64.3F.html#216832371">(Nov 16 2020 at 04:46)</a>:</h4>
<p>I used <code>rustup target add --toolchain nightly aarch64-unknown-linux-gnu</code>, and since clang knows how to compile for many architectures, I tried building some crates with <code>CC=clang-11 cargo +nightly build --target aarch64-unknown-linux-gnu</code>. However, this gave me errors when crates tried to compile C code, because clang seems to use the system headers, which don't work for aarch64. What's the Right Way to make this work?</p>



<a name="216833861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Cross-compiling%20for%20aarch64%3F/near/216833861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Cross-compiling.20for.20aarch64.3F.html#216833861">(Nov 16 2020 at 05:23)</a>:</h4>
<p>I think you need to tell clang to cross compile too</p>



<a name="216833874"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Cross-compiling%20for%20aarch64%3F/near/216833874" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Cross-compiling.20for.20aarch64.3F.html#216833874">(Nov 16 2020 at 05:23)</a>:</h4>
<p>Or the build scripts need to be fixed to detect TARGET and pass the right flags to clang</p>



<a name="216833930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Cross-compiling%20for%20aarch64%3F/near/216833930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Cross-compiling.20for.20aarch64.3F.html#216833930">(Nov 16 2020 at 05:24)</a>:</h4>
<p>FWIW this is the main reason builds fail when cross compiled on <a href="http://docs.rs">docs.rs</a>: <a href="https://internals.rust-lang.org/t/pre-rfc-build-only-one-target-by-default-on-docs-rs/12804">https://internals.rust-lang.org/t/pre-rfc-build-only-one-target-by-default-on-docs-rs/12804</a></p>



<a name="216836872"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Cross-compiling%20for%20aarch64%3F/near/216836872" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Cross-compiling.20for.20aarch64.3F.html#216836872">(Nov 16 2020 at 06:34)</a>:</h4>
<p><span class="user-mention silent" data-user-id="232545">Joshua Nelson</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Cross-compiling.20for.20aarch64.3F/near/216833861">said</a>:</p>
<blockquote>
<p>I think you need to tell clang to cross compile too</p>
</blockquote>
<p>The build scripts are doing so; the error messages show <code>clang-11</code> being invoked with <code>--target=aarch64-unknown-linux-gnu</code>.</p>



<a name="216894942"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Cross-compiling%20for%20aarch64%3F/near/216894942" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Cross-compiling.20for.20aarch64.3F.html#216894942">(Nov 16 2020 at 16:26)</a>:</h4>
<p>Do you have the glibc and/or the c++ standard library for aarch64 around?</p>



<a name="216894998"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Cross-compiling%20for%20aarch64%3F/near/216894998" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Cross-compiling.20for.20aarch64.3F.html#216894998">(Nov 16 2020 at 16:26)</a>:</h4>
<p>oh</p>



<a name="216895055"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Cross-compiling%20for%20aarch64%3F/near/216895055" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> simulacrum <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Cross-compiling.20for.20aarch64.3F.html#216895055">(Nov 16 2020 at 16:26)</a>:</h4>
<p><span class="user-mention" data-user-id="239881">@Josh Triplett</span> I believe <span class="user-mention" data-user-id="116155">@Jake Goulding</span> was saying that clang and rust have different target triples</p>



<a name="216895109"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Cross-compiling%20for%20aarch64%3F/near/216895109" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Cross-compiling.20for.20aarch64.3F.html#216895109">(Nov 16 2020 at 16:27)</a>:</h4>
<p>They do with respect to macOS, but I'm not sure about other platforms.</p>



<a name="216895155"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Cross-compiling%20for%20aarch64%3F/near/216895155" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Cross-compiling.20for.20aarch64.3F.html#216895155">(Nov 16 2020 at 16:27)</a>:</h4>
<p>I also remember having trouble getting clang to use those libraries, even if installed. I found gcc to work significantly better in cross-compilation contexts, personally.</p>



<a name="216895316"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Cross-compiling%20for%20aarch64%3F/near/216895316" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Cross-compiling.20for.20aarch64.3F.html#216895316">(Nov 16 2020 at 16:28)</a>:</h4>
<p>My gut would be it not linking to the correct libraries as well. Would have to see any of the errors to know.</p>



<a name="216906692"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Cross-compiling%20for%20aarch64%3F/near/216906692" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Cross-compiling.20for.20aarch64.3F.html#216906692">(Nov 16 2020 at 17:49)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116155">Jake Goulding</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Cross-compiling.20for.20aarch64.3F/near/216895316">said</a>:</p>
<blockquote>
<p>My gut would be it not linking to the correct libraries as well. Would have to see any of the errors to know.</p>
</blockquote>
<p>Not getting as far as linking; I'm hitting compilation errors. Specifically, the system headers don't know how to set <code>__WORDSIZE</code> to 64 for aarch64, and many other things follow from that, like <code>uintptr_t</code> having the wrong size.</p>



<a name="216906772"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Cross-compiling%20for%20aarch64%3F/near/216906772" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Cross-compiling.20for.20aarch64.3F.html#216906772">(Nov 16 2020 at 17:50)</a>:</h4>
<p><span class="user-mention silent" data-user-id="123586">nagisa</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Cross-compiling.20for.20aarch64.3F/near/216895155">said</a>:</p>
<blockquote>
<p>I also remember having trouble getting clang to use those libraries, even if installed. I found gcc to work significantly better in cross-compilation contexts, personally.</p>
</blockquote>
<p>Interesting. I would have expected clang to Just Work more here, since it has built-in multi-target support.</p>



<a name="216906865"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Cross-compiling%20for%20aarch64%3F/near/216906865" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Cross-compiling.20for.20aarch64.3F.html#216906865">(Nov 16 2020 at 17:51)</a>:</h4>
<p><span class="user-mention silent" data-user-id="123586">nagisa</span> <a href="#narrow/stream/182449-t-compiler.2Fhelp/topic/Cross-compiling.20for.20aarch64.3F/near/216894942">said</a>:</p>
<blockquote>
<p>Do you have the glibc and/or the c++ standard library for aarch64 around?</p>
</blockquote>
<p>No. I was expecting linking issues, but I didn't expect compilation issues.</p>
<p>I wish that glibc installed headers that worked on any architecture.</p>



<a name="216907077"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Cross-compiling%20for%20aarch64%3F/near/216907077" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jake Goulding <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Cross-compiling.20for.20aarch64.3F.html#216907077">(Nov 16 2020 at 17:53)</a>:</h4>
<p>Yeah, I shouldn't have used "linking", poor choice on my part. I meant more like "using".</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>